package com.example.controller;

import com.example.bean.Order;
import com.example.services.OrderProperties;
import com.example.services.OrderServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@RefreshScope
@RestController
public class OrderController {

    @Autowired
    private OrderServices orderServices;

//    @Value("${order.timeout}")
//    String timeout;
    @Autowired
    private OrderProperties orderProperties;

    @GetMapping("/config")
    public String getConfig() {
        return "Timeout: " + orderProperties.getTimeout();
    }

    @PostMapping("/create")
    public Order createOrder(@RequestParam Integer id, @RequestParam Integer userId) {
        return orderServices.createOrder(id, userId);
    }
}
